import time
import serial

CMD_GET_HT = '\x01'
CMD_SWITCH_ON = '\x02'
CMD_SWITCH_OFF = '\x03'
CMD_HELP_INFO = '\x04'

class Arduino(object):
    def __init__(self):
        self.port = serial.Serial("COM22", 9600, timeout=1)

    def get_help_info(self):
        self.port.write(CMD_HELP_INFO)
        line = self.port.readline()
        while line != '':
            print line
            line = self.port.readline()        

    def get_hum_temp(self):
        self.port.write(CMD_GET_HT)
        return self.port.readline()

    def turn_on_switch(self):
        self.port.write(CMD_SWITCH_ON)

    def turn_off_switch(self):
        self.port.write(CMD_SWITCH_OFF)        

if __name__=="__main__":
    arduino = Arduino()
    time.sleep(3)
    arduino.get_help_info()
    print arduino.get_hum_temp()
    arduino.turn_on_switch()
    time.sleep(10)
    arduino.turn_off_switch()
